import type { Component } from 'react';
type ViewComponent = Record<string, () => Promise<any>>;
const importViews = import.meta.glob('./**/*.tsx');
console.log(importViews, 'importViews');
const COMPONENTS_KEY = 'components';
const PREFIX = './';
const SUFFIX = '/.tsx';
const PREFIXMID = '/index.tsx';
/** 过滤掉组件文件 */
const viewKeys = Object.keys(importViews).filter(
  (key) => !key.includes(COMPONENTS_KEY),
);
console.log(viewKeys, 'viewKeys');
function getViewComponent() {
  const components: ViewComponent = {};
  viewKeys.forEach((key) => {
    const routeKey = key
      .replace(PREFIX, '')
      .replace(PREFIXMID, '')
      .replace(SUFFIX, '');
    components[routeKey] = importViews[key];
  });
  console.log(components, 'components');
  return components;
}

export const views = getViewComponent();
